import {
	getAllCommentary,
	getTwoCommentary,
	putCommentary
} from '@/api/commentary.js';
const state = {
	CommentData: []
}
const actions = {
	//拿到所有一级评论
	async GetAllFirstCommentary(context, data) {
		let {
			articleId,
			current,
			size
		} = data;
		let res = await getAllCommentary(parseInt(articleId), current, size);

		if (res.data.code === 0) {
			context.commit("GETALLONECOMMENT", res.data.result.list);
			return 'ok';
		} else {
			return 'false';
		}
	},
	//根据一级评论拿到二级评论
	async GetTwoCommentary(context, rootId) {
		let res = await getTwoCommentary(rootId);
		console.log("二级评论 " + res);
	},
	//发布评论
	async PutCommentary(context, data) {
		let res = await putCommentary(data);
		if (res.data.code === 0) {
			return 'ok';
		} else {
			return 'false';
		}
	}

}
const mutations = {
	GETALLONECOMMENT(state, data) {
		state.CommentData = data
	}
}
const getter = {

}

export default {
	state,
	actions,
	mutations,
	getter
}
